<template>
  <div>
    <!--    <a-spin :spinning="spinning"/>-->
    <a-form ref="formRef" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol" style="margin-top: 46px">
      <a-col :lg="16">
        <a-form-item label="网站名" name="name">
          <a-input placeholder="请输入网站名" v-model:value="queryParam.name"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="网站域名" name="domain">
          <a-input placeholder="请输入网站域名" v-model:value="queryParam.domain"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="SEO关键词" name="keyword">
          <a-input placeholder="请输入SEO关键词" v-model:value="queryParam.keyword"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="网站描述" name="description">
          <a-input placeholder="请输入网站描述" v-model:value="queryParam.description"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="站长QQ" name="qq">
          <a-input placeholder="请输入站长QQ" v-model:value="queryParam.qq"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="网站logo图片（默认）" name="logo">
          <a-input placeholder="请输入网站logo图片（默认）" v-model:value="queryParam.logo"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label="网站logo图片（深色）" name="logoDark">
          <a-input placeholder="请输入网站logo图片（深色）" v-model:value="queryParam.logoDark"></a-input>
        </a-form-item>
      </a-col>
      <a-col :lg="16">
        <a-form-item label=" " name="" :colon="false">
          <a-button type="primary" @click="clickSubmit">保存</a-button>
        </a-form-item>
      </a-col>
    </a-form>
  </div>
</template>

<script lang="ts" name="novel-websiteInfo" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './WebsiteInfo.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './WebsiteInfo.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import WebsiteInfoModal from './components/WebsiteInfoModal.vue'
  import { defHttp } from '/@/utils/http/axios';
  import { message } from 'ant-design-vue';
  const formRef = ref();

  let queryParam = reactive<any>({
    name:'',
    domain:'',
    keyword:'',
    description:'',
    qq:'',
    logo:'',
    logoDark:'',
    id:''
  });
  async function init(){
    const data=await defHttp.get({ url: '/novel/websiteInfo/queryById' })
    for (const key in queryParam) {
      queryParam[key]=data[key]
    }
    spinning.value=false
  }

  init()
  const spinning=ref<boolean>(true)
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: 'website_info',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: "website_info",
      url: getExportUrl,
      params: queryParam,
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add();
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }

  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }

  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }

  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      }, {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
        }
      }
    ]
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }


  async function clickSubmit() {
    let url=queryParam.id===''?'/novel/websiteInfo/add':'/novel/websiteInfo/edit'
    const data=await defHttp.post({ url, params:queryParam })
    message.success('操作成功');
  }




</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
